package com.front.peikuahaitao.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.front.peikuahaitao.R;
import com.front.peikuahaitao.base.MvpActivity;
import com.front.peikuahaitao.bean.User;
import com.front.peikuahaitao.presenter.LoginPresenter;
import com.front.peikuahaitao.view.impl.ILoginView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class LoginActivity extends MvpActivity<ILoginView, LoginPresenter> implements ILoginView {


    @BindView(R.id.toolbar_login)
    Toolbar toolbarLogin;
    @BindView(R.id.tab_login)
    TabLayout tabLogin;
    @BindView(R.id.button_login)
    Button buttonLogin;
    @BindView(R.id.edit_text_username)
    EditText editTextUsername;
    @BindView(R.id.edit_text_password)
    EditText editTextPassword;

    @Override
    public LoginPresenter initPresenter() {
        return new LoginPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {

//        BmobConfig config =new BmobConfig.Builder(this)
//        //设置appkey
//        .setApplicationId("4a53fa04d50a57b56b92329de2b98d41")
//        //请求超时时间（单位为秒）：默认15s
//        .setConnectTimeout(30)
//        //文件分片上传时每片的大小（单位字节），默认512*1024
//        .setUploadBlockSize(1024*1024)
//        //文件的过期时间(单位为秒)：默认1800s
//        .setFileExpiration(2500)
//        .build();
//        Bmob.initialize(config);
        toolbarLogin.setTitle("登录");
        toolbarLogin.setNavigationIcon(R.drawable.base_btn_back_normal);
        setSupportActionBar(toolbarLogin);
        toolbarLogin.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    @OnClick(R.id.button_login)
    public void onClick() {
        String userName = editTextUsername.getText().toString();
        String passWord = editTextPassword.getText().toString();
        presenter.userLogin(userName,passWord);
    }


    @Override
    public void onSuccess(String userName) {
        Toast.makeText(LoginActivity.this, "账号"+userName, Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onFail(String passWord) {
        Toast.makeText(LoginActivity.this, "密码"+passWord, Toast.LENGTH_SHORT).show();
    }
}
